// 这个系统共用状态管理
import {MenuThemeEnum, SystemConfig, SystemThemeEnum} from "@/types/layouts.ts";

export const useLayouts = defineStore({
    id: 'useLayouts',
    state: (): SystemConfig => {
        return {
            aside: {
                showLogo: true,
                isCollapse: false,
                withoutAnimation: false
            },
            header: {
                isFixed: true,
                isDrawer: false,
                showBreadCrumb: true,
                showCollapse: true,
                showDoc: true,
                showFullScreen: true,
                showLang: true,
                language: 'zh-CN',
                showNotify: true,
                showProfile: true,
                showRefresh: true,
                showSearch: true,
                showSetting: true,
                showTagsView: true,
                showTagsViewBar: true
            },
            main:{
                isKeepAlive: false,
                showPadding: true
            },
            footer: {
                content: '© 2022 - 2023',
                showFooter: true
            },
            theme: {
                system: SystemThemeEnum.LIGHT,
                menu: MenuThemeEnum.LIGHT,
                showBorder: false,
                showGlass: false,
                showBorderRadius: false,
                showShadow: false
            }
        }
    },
    getters: {
        getRoutes: (state) => {
            return state.routes
        }
    },

    // actions 中并不对应 setter 方法，而是关于这个 store 的所有请求调用封装
    // 在这里面调用 api 目录中对应的请求接口，不要在文件组件中进行调用，而是统一在 store 中调用
    actions: {
        initStore() {
            const systemTheme = localStorage.getItem('systemTheme')
            if (systemTheme) {
                this.theme = JSON.parse(systemTheme)
            } else {
                this.theme = {
                    system: SystemThemeEnum.LIGHT,
                    menu: MenuThemeEnum.LIGHT,
                    showBorder: false,
                    showGlass: false
                }
            }
        },
        setSystemTheme(theme: SystemConfig) {
            this.theme = theme
        },
        setMenuTheme(theme: SystemConfig) {
            this.theme = theme
        },
        seAsideLogo() {
            this.aside.showLogo = !this.aside.showLogo
        },
        setHeaderFixed() {
            this.header.isFixed = !this.header.isFixed
        },
        setHeaderBreadCrumb() {
            this.header.showBreadCrumb = !this.header.showBreadCrumb
        },
        setHeaderCollapse() {
            this.header.showCollapse = !this.header.showCollapse
        },
        setHeaderDoc() {
            this.header.showDoc = !this.header.showDoc
        },
        setHeaderFullScreen() {
            this.header.showFullScreen = !this.header.showFullScreen
        },
        setHeaderLang() {
            this.header.showLang = !this.header.showLang
        },
        setHeaderNotify() {
            this.header.showNotify = !this.header.showNotify
        },
        setHeaderProfile() {
            this.header.showProfile = !this.header.showProfile
        },
        setHeaderRefresh() {
            this.header.showRefresh = !this.header.showRefresh
        },
        setHeaderSearch() {
            this.header.showSearch = !this.header.showSearch
        },
        setHeaderSetting() {
            this.header.showSetting = !this.header.showSetting
        },
        setHeaderTagsView() {
            this.header.showTagsView = !this.header.showTagsView
        },
        setHeaderTagsViewBar() {
            this.header.showTagsViewBar = !this.header.showTagsViewBar
        },
        setMainPadding() {
            this.main.showPadding = !this.main.showPadding
        },
        setFooterContent() {
            this.footer.content = '© 2022 - 2023'
        },
        setFooterShow() {
            this.footer.showFooter = !this.footer.showFooter
        }
    },

    // 持久化存储
    // persist: {
    //     key: 'layoutConfig',      // 存储的 key 值，默认为 store.$id
    //     storage: localStorage,   // 存储的实例，默认为 localStorage
    //     //paths: ['theme'],        // 需要持久化的 state 值，默认为全部
    // }
})
